<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增套餐')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-meal-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐名称：</label>
                <div class="col-sm-8">
                    <input name="mealName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐同时在线数：</label>
                <div class="col-sm-8">
                    <input name="useCount" class="form-control" type="number" value="1" required="digits">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐周期（小时）：</label>
                <div class="col-sm-8">
                    <input name="useHour" class="form-control" type="number" required="digits">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐金额（元）：</label>
                <div class="col-sm-8">
                    <input name="price" id="price" class="form-control" type="number" required="min:0">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('radius_meal_status')}">
                        <input type="radio" th:id="${dict.dictCode}" name="enable" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sortNumber" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "radius/meal"
        $("#form-meal-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var form = $('#form-meal-add').serializeArray();
                form.forEach(item =>{
                    if(item.name == "price"){
                        item.value = Math.round($("#price").val() * 100) + "";;
                        return;
                    }
                })
                $.operate.save(prefix + "/add", form);
            }
        }
    </script>
</body>
</html>